package chapter12

import scala.collection.mutable.ArrayBuffer

/**
  * @Copyright: Shanghai Definesys Company.All rights reserved.
  * @Description:
  * @author: chuhaitao
  * @since: 2019/1/14 22:37
  * @history:
  *          1.2019/1/14 created by chuhaitao
  */
object FoldDemo02 {


  def main(args: Array[String]): Unit = {
    //1
    var seq = "AAAAAAAAAAAAAAAAAADDDDDDDDDDDDDDDDFFFFFFFFFFFFFFFTTTTTTTTTT"
    // val arrayBuffer = new ArrayBuffer[Char]()
    var arr = seq.foldLeft(new ArrayBuffer[Char]())((arrayBuffer: ArrayBuffer[Char], n1: Char) => {
      arrayBuffer.append(n1)
      arrayBuffer
    })


    println("arr:" + arr)
    //2 统计每个单词的数量

    var count = seq.foldLeft(Map[Char, Int]())((map: Map[Char, Int], char: Char) => {

      map + (char -> {
        map.getOrElse(char, 0) + 1
      })
    })

    println("count:" + count)
  }
}
